package com.lits.search.hotKeys.dto;

/**
 * 关键字实体类<p>
 * 相同的key，weight的对象被认为是一个对象
 * @author Lizm
 *
 */
public class HotKey implements Comparable<HotKey>{
	/**
	 * 关键字索引
	 */
	private long id;
	
	/**
	 * 关键字
	 */
	private String key;
	
	/**
	 * 关键字hash
	 */
	private int keyHash;
	
	/**
	 * 如果是汉字，汉字的拼音值
	 */
	private String pinYin;
	
	/**
	 * 关键字被使用次数
	 */
	private int weight;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
		this.keyHash = key.hashCode();
	}

	public int getKeyHash() {
		return keyHash;
	}

	public void setKeyHash(int keyHash) {
		this.keyHash = keyHash;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}
	
	public String getPinYin() {
		return pinYin;
	}

	public void setPinYin(String pinYin) {
		this.pinYin = pinYin;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : key.hashCode());
		result = prime * result + weight;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		HotKey other = (HotKey) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!key.equals(other.key))
			return false;
		if (weight != other.weight)
			return false;
		return true;
	}

	public int compareTo(HotKey o) {
		if(o == null) return 1;
		return this.getWeight() - o.getWeight();
	}
	
	
	
}
